package com.sec.etech.employeesync.confighandler;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sec.etech.employeesync.entity.OrgEmployeeZCompany;
import com.sec.etech.employeesync.mapper.OrgEmployeeZCompanyMapper;
import com.sec.etech.employeesync.util.ConfigTableHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class CompanyConfigHandler implements ConfigTableHandler<OrgEmployeeZCompany> {

    @Resource
    private OrgEmployeeZCompanyMapper companyMapper;

    @Override
    public Long getOrCreateConfigId(String... params) {
        String code = params[0];
        OrgEmployeeZCompany company = getEntityByName(code);
        if (company == null) {
            return null;
        }
        return company.getCompanyId();
    }

    @Override
    public OrgEmployeeZCompany getEntityByName(String code) {
        return companyMapper.selectOne(Wrappers.<OrgEmployeeZCompany>lambdaQuery()
                .eq(OrgEmployeeZCompany::getCode, code));
    }

    @Override
    public String generateNextCode() {
        return null;
    }

    @Override
    public void insertEntity(OrgEmployeeZCompany entity) {
    }
}
